package level4.iso
{
	import flash.display.Sprite;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	
	import level4.display.GameDispose;
	import level4.interfaces.IGameComponent;
	/**
	 * 等角对象基类
	 * */
	public class IsoObject extends GameDispose implements IGameComponent
	{
		private var size:Number;
		private var isoPoint:Point3D;
		private var screenPoint:Point;
		private var walkable:Boolean;
		
		private var invalid:Boolean;
		
		private var vx:Number = 0;
		private var vy:Number = 0;
		private var vz:Number = 0;
		
		public function IsoObject(size:Number)
		{
			isoPoint = new Point3D();
			this.size = size;
			invalid = true;
		}
		//重绘此等角对象
		public function update(timeDiff:Number):void{
			if(invalid){
				screenPoint = IsoUtil.IsoToScreen(isoPoint);
				super.x = screenPoint.x;
				super.y = screenPoint.y;
				invalid = false;
			}
		}
		//设置 等角对象的在等角世界的位置
		public function setIsoPoint(x:Number,y:Number,z:Number):void{
			isoPoint.x = x;
			isoPoint.y = y;
			isoPoint.z = z;
			invalid = true;
		}
		public function move():void{
			IsoPoint.x += vx;
			IsoPoint.y += vy;
			IsoPoint.z += vz;
			invalid = true;
		}
		public function stopMove():void{
			vx = vy = vz = 0;
		}
		override public function toString():String{
			return "IsoObject("+isoPoint+")";
		}
		
		///////////////////
		//Getter Setter
		///////////////////
		public function get IsoPoint():Point3D{
			return isoPoint;
		}
		public function set IsoPoint(pos:Point3D):void{
			this.isoPoint = pos;
			invalid = true;
		}
		//获取等角对象在屏幕坐标的位置点
		public function get ScreenPoint():Point{
			return screenPoint;
		}
		//返回占用的矩形区域
		public function get Rect():Rectangle{
			return new Rectangle(x - size/2,z - size/2,size,size);
		}
		//是否可以移动
		public function get Walkable():Boolean{
			return walkable;
		}
		public function set Walkable(value:Boolean):void{
			this.walkable = value;
		}
		//大小
		public function get Size():Number{
			return size;
		}
		//返回此等角对象所在位置的深度(z)公式: (x+z)*0.866-y*0.707
		public function get depth():Number{
			return (isoPoint.x + isoPoint.z) * 0.866 - isoPoint.y * 0.707;
		}
		
		public function get Vx():Number{
			return vx;
		}
		public function set Vx(value:Number):void{
			vx = value;
		}
		public function get Vy():Number{
			return vy;
		}
		public function set Vy(value:Number):void{
			vy = value;
		}
		public function get Vz():Number{
			return vz;
		}
		public function set Vz(value:Number):void{
			vz = value;
		}
	}
}